Skip to content

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Sep 22, 2025

This was detected in #1582 (comment)

It was a very subtle old inconsistency between the default value used in the hash and equality methods of ScalarOps

This fix should be a blocker for the next release.


📚 Documentation preview 📚: https://pytensor--1616.org.readthedocs.build/en/1616/

@ricardoV94 ricardoV94 added bug Something isn't working Op implementation labels Sep 22, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request fixes a backwards compatibility issue in ScalarOp hash calculation. The problem was an inconsistency between the default values used in hash and equality methods, where hash used 0 while equality used None for the output_types_preference attribute. This inconsistency caused C-caching errors when comparing old cached operations with fresh ones.

  • Aligns the default value in the __hash__ method to use None instead of 0
  • Adds a test to verify hash consistency between old and new ScalarOp instances

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pytensor/scalar/basic.py Changes default value in __hash__ method from 0 to None
tests/scalar/test_basic.py Adds test case to verify hash consistency for backwards compatibility

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@ricardoV94 ricardoV94 force-pushed the scalar_hash_default_bug branch from 0f3a014 to 5e7a46e Compare September 22, 2025 08:41
test = type(self) is type(other) and getattr(
return type(self) is type(other) and getattr(
self, "output_types_preference", None
) == getattr(other, "output_types_preference", None)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the None default instead of 0 that was used in the hash. That was the issue

@ricardoV94 ricardoV94 force-pushed the scalar_hash_default_bug branch from 5e7a46e to bfe92a3 Compare September 22, 2025 08:55
Copy link

codecov bot commented Sep 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.64%. Comparing base (ee107cb) to head (bfe92a3).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1616      +/-   ##
==========================================
- Coverage   81.64%   81.64%   -0.01%     
==========================================
  Files         231      231              
  Lines       52998    52997       -1     
  Branches     9395     9395              
==========================================
- Hits        43268    43267       -1     
  Misses       7282     7282              
  Partials     2448     2448              
Files with missing lines Coverage Δ
pytensor/scalar/basic.py 80.58% <100.00%> (-0.01%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jessegrabowski
Copy link
Member

Sorry my report of this issue wasn't clearer. But luckily you still tracked it down!

@ricardoV94
Copy link
Member Author

No, it was great that you noticed. This was an ugly one to have missed

@ricardoV94 ricardoV94 merged commit 96122d1 into pymc-devs:main Sep 23, 2025
159 of 164 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants